define(function(require, exports, module) {

	//基础格式判断
	$.extend({
		testAct: function(str,reg){
			return(reg.test(str));
		},
		testBasic: function(str){
			var bl = str ? true : false;
			return(bl);
		},
		testMail: function(str){
			var myReg = /^[.-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$/;
			return($.testAct(str,myReg));
		},
		testPass: function(str){
			var myReg = /^[a-z0-9_-]{3,18}$/;
			return($.testAct(str,myReg));
		},
		testIP: function(str){
			var myReg = /((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)/;
			return($.testAct(str,myReg));
		},
		testChineseName: function(str){
			var myReg = /^[\u2E80-\u9FFF]+$/;
			return($.testAct(str,myReg));
		},
		testNumber: function(str){
			var myReg = /^[0-9]/;
			return($.testAct(str,myReg));
		},
		testMobile: function(str){
			var myReg = /^(1(([35][0-9])|(47)|[8][0123456789]))\d{8}$/;
			return($.testAct(str,myReg));
		},
		testPhone: function(str){
			var myReg = /^\d{10,12}$/;
			return($.testAct(str,myReg));
		},
		queryString: function(str){
			var sValue=location.search.match(new RegExp("[\?\&]"+str+"=([^\&]*)(\&?)","i"));
			return sValue?sValue[1]:sValue;
		},
		baseName: function(str){
			var base = new String(str).substring(str.lastIndexOf('/') + 1);
      		if(base.lastIndexOf(".") != -1) {
        		base = base.substring(0, base.lastIndexOf("."));
      		}
      		return base;
		},
		updateQueryStringParameter: function(uri, key, value){
			var re = new RegExp("([?|&])" + key + "=.*?(&|$)", "i");
      		separator = uri.indexOf('?') !== -1 ? "&" : "?";
      		var url = window.location.href;
      		if (uri.match(re)) {
        		url = uri.replace(re, '$1' + key + "=" + value + '$2');
      		}
      		else {
        		url = uri + separator + key + "=" + value;
      		}
      		return url;
		},
		randomNumber: function(){ //四位随机数或者字母
			function only(ele,arr){
				if(arr.length==0){
					return true;
				}
				for(var j=0;j<arr.length;j++){
					if(ele==arr[j]){
						return false;
					}else{
						return true; 
					}
				}
			}
			var arr=[0,1,2,3,4,5,6,7,8,9,"a","b","c","d","e","f","g"];
			var str="";
			(function(){
				var randNum=null;
				var old=[];
				function done(){
					randNum=Math.floor(Math.random()*14);
					if(only(randNum,old)){
						str=str+arr[randNum];
						old.push(randNum);
					}else{
						done();
					}
				}
				for(var index=0;index<4;index++){
					done();
				};
			})(arr);
			return str;
		},
        checkBrowser: function(){ //检查浏览器和版本
            var	userAgent=navigator.userAgent;
		    //console.log(userAgent);
		    var os = {};
		    os.android = userAgent.match(/(Android)\s+([\d.]+)/) || userAgent.match(/Silk-Accelerated/) ? true : false;
		    os.androidICS = os.android && userAgent.match(/(Android)\s4/) ? true : false;
		    os.ipad = userAgent.match(/(iPad).*OS\s([\d_]+)/) ? true : false;
		    os.iphone = !os.ipad && userAgent.match(/(iPhone\sOS)\s([\d_]+)/) ? true : false;
		    os.ios = os.ipad || os.iphone;
		    os.wp=userAgent.match(/Windows Phone/) || userAgent.match(/IEMobile/) ? true : false;
		    os.supportsTouch = ((window.DocumentTouch && document instanceof window.DocumentTouch) || 'ontouchstart' in window);
            os.lessIE10 = document.all && !window.atob; //Internet Explorer ≤ 9
            os.lessIE9 = document.all && !document.addEventListener;; //Internet Explorer ≤ 8
            os.isWeixin = userAgent.toLowerCase().match(/MicroMessenger/i)=='micromessenger';
		    return os;
        }
	});
});

